package com.tttshaoqi.server.controller;

import com.tttshaoqi.common.result.Result;
import com.tttshaoqi.server.service.OssService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/api/oss")
@RequiredArgsConstructor
public class UploadController {

    private final OssService ossService;

    @PostMapping("/image")
    public Result<Map<String, Object>> uploadImage(MultipartFile file) {
        if (file == null || file.isEmpty()) return Result.error("文件为空");
        String url = ossService.uploadImage(file);
        return Result.success(Map.of("url", url));
    }
}



